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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JAVASCRIPT !!!! HELLLLP

Status
Not open for further replies.

AMDERBO

IS-IT--Management
Mar 7, 2007
6
CH
Hi
i'm trying to make a script that opens a random link from the page contained in an iframe after 5 seconds .... very hard
that's what i done :

<head></head><body>
<script>
<!--
function random_all(){
var myrandom=Math.round(Math.random()*(document.links.length-1))
window.location=document.links[myrandom].href
}
//-->
</script>

<a href="javascript:random_all()">Random Link</a>

<iframe id="frame" frameborder="0" vspace="0" hspace="0" marginwidth="0" marginheight="0" width="100%" height="100%" src="
</iframe>
</body>

Thanks for your help
 
Is this spam? I don't know if I want to help someone create more fodder for popup blockers.

[monkey][snake] <.
 
Hi
it's not a popup 'cause the link href="javascript:random_all()" is a random link that only opens when someone clics on it. it doesnt open a popup it's a sort of random redirection ...
 
So if I understand this correctly, when a user clicks on the anchor "Random Link", after 5 seconds you want an iframe to popup that contains a random page from the list of links that are in the main page??

If I understand I can help you out.

[monkey][snake] <.
 
well what i want exactly is to make a script that redirects the user after 5 sec to a random link contained in the iframe . the redirection is made in the same window and without any popups
Thanks for your help
 
If you are trying to grab the links from an external source that is in the iframe, I don't think that is possible.

If you are creating the iframe content though, then it is possible.

[monkey][snake] <.
 
yep i'm trying to grab and external link
 
I took your code at the top and modified it. Although you can modify it some more and place it on the onload event then you have your popups...:)

<%@ Language=JScript %>
<html>
<head>
<script language="javascript">
<!--
function random_all(){
var myrandom=Math.round(Math.random()*(document.links.length-1))
alert(myrandom);

//window.location=document.links[myrandom].href

}
//-->
</script>

</head>
<body>


<a href="javascript:random_all()">Random Link</a>
<a href=" onclick="javascript:random_all()">microsoft</a>
<a href=" onclick="javascript:random_all()">goolge</a>


<iframe id="frame" frameborder="0" vspace="0" hspace="0" marginwidth="0" marginheight="0" width="100%" height="100%" src="
</iframe>
</body>
</html>
 
This is a dev based on the script shown but fully corrected. In this demo, the exact meaning of cross-domain security clearance is demonstrated as well. The page in the iframe should be remaining in the same domain (sub-domains etc...) But that domain may be differed from the parent page's domain.
[tt]
<html>
<head>
<script language="javascript">
<!--
function random_all(){
var myrandom=Math.floor(Math.random()*(document.links.length-1))+1;

var shref=document.links[myrandom].href;
document.getElementById("frame").src=shref;
//return false; //no really needed in this config
}
//-->
</script>
</head>
<body>
<a href="javascript:void random_all()">Random Link</a> <!-- void here is necessary -->
<a href=" sidebar</a>
<a href=" Constants</a>

<iframe id="frame" frameborder="0" vspace="0" hspace="0" marginwidth="0" marginheight="0" width="100%" height="100%" src=" frame supported required</iframe>
</body>
</html>
[/tt]
Click on the random link to show the effect. The other link will bring you away from the page.
 
I think we're missing the point. The poster wants any random external link from a site, not just those contained in anchors on the calling page. This supposes that the system knows all of the pages on the target site, or else you'd get a 404.

Not doable without some kind of spidering activity against the target sites.
 
The poster wants any random external link from a site

Correct philhege.

More specifically a site that is contained in an iframe on the poster's site.

[monkey][snake] <.
 
Do something like parent.frames(0)... could be used to enumerate the anchors in the iframe, right?

Phil Hegedusich
Senior Programmer/Analyst
IIMAK
-----------
Not NULL-terminated yet.
 
It's totally impossible for you to get the information in an iframe when you are loading the data through a <iframe [!]src="blah.html"[/!]> setup.

[monkey][snake] <.
 
If you are not even able to change "internal" link, you have the luxury to say you want to change "external"? How about document.links.length? Does it appear for no reason? document.links... do you mean world.document.links? Spider? If you need advice on spider, you have to ask. But you don't get away by pretending the subject is something else.
 
ok thanks you made things clear in my mind i need a kind of spidering engine i will rentacoder :)
thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top