Solved

How to change onclick destination url in parent frame.

Posted on 2008-10-16
4
1,270 Views
Last Modified: 2009-01-28
Okay i have Main Frame which has an iframe inside it.

in main frame there is image

<td rowspan="3" valign="top"><a href="#"><img src="template_05.gif" width="172" height="45" border="0" onclick="openw('https://www,google.com',0,0,0,0,0,1,1,900,900,200,1,1);" value="openw"/></a></td>

now www.google.com i need to change to www.yahoo.com

i have the code which does it but only in iframe .It doesn't change the main frame img.How can i override it?


<script language="JavaScript">
// THIS IS THE CODE TO CHANGE URL FOR THE CURRENT FRAME
function rpl (){
        var imgs = document.getElementsByTagName("img");
        for(var i = 0; i < imgs.length; i++) {
                var img = imgs[i];
                if(img.getAttribute("value") == "openw") {
                        img.setAttribute("onclick", imgs[i].getAttribute("onclick").replace("https://www.google.com", "http://www.yahoo.com"));
                }
        }
        }
        window.onload=rpl;
</script>

Open in new window

0
Comment
Question by:olivest
4 Comments
 

Accepted Solution

by:
olivest earned 0 total points
ID: 22732706
Just realised need to add little word "parent" in front of document.getElementsByTagName("img");
0
 
LVL 8

Expert Comment

by:MatthiasVance
ID: 22732739
I was *just* about to post that indeed. Good luck with it!

Kind regards,

Matthias Vance
0
 
LVL 19

Expert Comment

by:NerdsOfTech
ID: 22805504
opener.[object] to reference the opener frame (popup)
OR
parent.[object] to reference the parent frame
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question