I have an Iframe or just a frame and I want it to show a random url each time, is there any script to do so ?
And another one; I have a page with 2 frames, the first one has some content and the second shows the url "www.google.com", the user enters a search term and clicks "search". What I want is that when he clicks "search" the second frame redirects him to the "results page" and the first frame redirect to another page "page1".
Like, on second frame exit, first frame redirect is activated. Any way I can do so (like onExit or onUnload)
You can simply put the URLs that you want in an array, and use Math.random() to generate a random number (which is between 0 & 1, so you have to multiply it by the array's length and use Math.floor() on it). Use the random number as the array's index to get a random URL of the ones stored in the array, and use it as the source for the frame (or the iframe).
As for the second question, it's a little tricky. The simplest google search url is www.google.com/search?q=searchTerm. If the search term is made up of several words, they are separated by a + sign instead of spaces. Of course you have to take care of the special characters that google use marks to move the search to a specific direction (like the + sign to assure that the following word is present or the - sign to make sure that the following word is not present, etc). This can be done by taking the search term, splitting it into spaces, and using the escape() method on each part of the search term to generate the search URL.
[ February 12, 2008: Message edited by: Alaa Nassef ] [ February 12, 2008: Message edited by: Alaa Nassef ]
There are a couple of problems that I didn't mention. The smaller of them, which is not actually a real problem, is that google uses other attributes in the URL to specify the browser, the encoding, and other stuff. This is not a real problem, since you can get some of the attributes yourself, and if you didn't specify them, the defaults will not cause any trouble in the normal cases.
The second problem is the real problem, and that is you want the first frame to point at www.google.com, and if you do that, you'll not be able to make the search button make the search be done in the second frame; except of course if you change the code. You can either create your own search page, and use it in the first frame, or you can parse the html of www.google.com, and change the action of the submit button to make it display the search page in the second frame.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com