Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Script works in IE but not in Chrome/firefox...

Status
Not open for further replies.

Nogi12345

Technical User
Jul 12, 2010
4
BE
I have an external javascript running that i downloaded from the internet and used in my html page. It lets links being displayed in an iframe.

Here's the script:

Code:
/*************************************************************************
    This code is from dyn-web.com
    free for all uses as long as this notice retained
*************************************************************************/

/*  dw_loader.js      version date: July 2008
    loads url in iframe, transfers body content into div
    provides defaults for iframe and display div ID's 
    also supports use with multiple iframes and divs
    optional message for loading in display div 
    supports functions to be called once the div has been populated with new content 
    function in iframed document can be invoked should some operations need to be performed from there 
*/

function dw_loadExternal(url, ifrmId, divId, bLoadMsg) {
    // defaults for iframe, display div
    ifrmId = ifrmId || 'buffer'; divId = divId || 'display'; 
    if ( window.frames[ifrmId] ) {
        // Could use location.replace method if you do not want back button to load previous iframe url 
        //window.frames[ifrmId].location.replace(url);
        window.frames[ifrmId].location.replace(url);
        // If you want the whole page to scroll to the top when new content is loaded 
        //window.scrollTo(0,0);
        var lyr = document.getElementById? document.getElementById(divId): null;
        if ( lyr && bLoadMsg ) { // Option to display message while retrieving data 
            lyr.innerHTML = '<p>Retrieving data. Please wait ...</p>';
            lyr.style.display = 'block'; 
        }
        return false;
    } 
    return true; // other browsers follow link
}

Inside the html, this is the code i use for the iframe:

Code:
<div id="display"><p><!--webbot
    bot="HTMLMarkup" startspan --><IFRAME id="buffer" name="buffer" height="100%" frameborder="0" width="100%" src="section.htm" onload="dw_displayExternal(this.href)"><!--webbot bot="HTMLMarkup" endspan --><!--webbot
    bot="HTMLMarkup" startspan --></IFRAME><!--webbot bot="HTMLMarkup" endspan --></p>
    </div>

The code for triggering a link inside the html:

Code:
<a
    href="purchasing/Section_00rev.htm" onclick="return dw_loadExternal(this.href)">Section<strong>
    00</strong></a>

For some reason, this script works great in IE, but it doesn't work in Chrome (links don't respond at all) and in Firefox (works, but frame is veeeery tiny).

I can't figure out how to change it to make it work on IE and the others.
Can somebody help me out pls?

Thanks in advance for the efford
 
Call me old-fashioned, but why on earth would you want to use JavaScript to open a link in a frame / iframe?

Why not simply use the "target" attribute of the anchor element (assuming you either don't care about validation, or are using a DOCTYPE that allows it) ?

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml"[/URL] xml:lang="en" lang="en">
<head>
	<meta http-equiv="content-type" content="text/html; charset=utf-8" />
	<meta http-equiv="content-language" content="en" />

	<title>IFrame test</title>
</head>

<body>
	<p><a href="[URL unfurl="true"]http://www.google.co.uk/"[/URL] target="frame1">Google</a></p>
	<p><a href="[URL unfurl="true"]http://www.coedit.co.uk/"[/URL] target="frame2">Coedit</a></p>
	
	<iframe name="frame1" src="about:blank"></iframe>
	<iframe name="frame2" src="about:blank"></iframe>
</body>

</html>

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Snippets & Info:
The Out Atheism Campaign
 
Well i first had just a simple Iframe setup, with links as you mention targeted to the iframe, and it works like a charm in chrome/firefox, but it didn't in IE.

So when looking for a solution, i came accross what i posted above, but annoying enough it does now work in IE, but not anymore in Chrome.

So i need a solution that works in both heh.
 
Ok, i will try it out immediately Dan.

Thanks for your fast reply
 
Works like a charm now Dan. I don't really understand why it didn't work in the first place, but thanks for your effords :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top