Append parameter to page inside iframe - html

I am making a tiny bot-like page that will redirect the user to a certain page plus a paramater.
Basically:
A page inside an iframe redirects the user to a random page on my site (already done)
The script appends ?action=purge to the page inside the iframe
The script refreshes the page after 1 second (already done)
The part I need is the middle part, I have no idea how to do that. I know you can use the meta refresh to redirect, but how do you make it so the URL reads the iframe's URL plus ?action=purge"

Try this:
var src1 = document.getElementById('id_of_the_iframe').getAttribute('src');
var src2 = src1 + '?action=purge';
document.getElementById('id_of_the_iframe').setAttribute('src',src2);
If this doesn't work or is not what you are looking for then I don't know.
Edit:
Make sure you call the script after the page has loaded, since you can't change what hasn't been loaded into the DOM in a page yet.

Related

Why does an iframe URL redirect to the main page?

I have a simple react application containing an iframe. I want to reference a paragraph inside that iframe that has a specific id. For example, having <p id="test">Test</p>, I would like to reference it with localhost:8000/my-local-iframe.html#test.
If I access this URL directly, it gives me a full view of the iframe, like it would be the main application. If I want to access this URL from an anchor, I get redirected to the homepage, in this case, localhost:8000.
A strange interaction I've noticed is that whenever I click the anchor while inspecting the page, I don't get redirected anymore and the link works as expected.
Can anyone explain why this happens and how could I avoid the redirect?

How to set current url so relative links resolve correctly when injecting custom html in puppeteer?

I am trying to create a new page and manually set its content. Because the url of a blank page with injected code is still about:blank, all of the relative links on the page are broken. Is there a way to set the url of the page without actually navigating to that url via goto?
I can think of two options:
Create a function to turn a relative path into a file:// URL.
Run a simple server. I wrote a post about that on my blog

share iframe with specific content

Lets say i have a website called http://123.com.
The index.html page of the website contains an iframe called theframe.
i have three different page (1.html, 2.html, 3.html) for the iframe content and they will be displayed when i click specific button in the site. The default content of the iframe is 1.html.
My question is, if i need to share http://123.com with 2.html or 3.html displayed on the iframe, how should i write the link on facebook/blog/IM to share? Is there a way without modifying the website?
Thank you.
you have hard coded value in iframe src
use querystring
make a parameter named dstntn palce in your url
http://123.com/?dstntn=your_url
and then get it in a var by $_REQUEST['dstntn'];
and give var to iframe src
then change iframe by changing dstntn value by 1.html || 2.html
NOTE: read encoded and decoded form for query string i think dots are not acceptable

how to send information to page

My website consists mainly of pages that are loaded into an iframe on the homepage.
When the pages are loaded they check if they have been opened outside the iframe and if they are the homepage is opened.
Now I want to open this specific page when the homepage is opened.
How do I send the information that the "browser came from" test.html? And then set the source of the iframe to be test.html?
The syntax
top.document.referrer
will let you access the parent of the iFrame;
document.getElementById('myIframeId').src = myUrl + 'test.html';
will set the iFrame source.
Pass the URL of the page to be framed in the query string of the URL to the page containing the frame.

Is there any way to request a page without displaying it?

If you link to something downloadable with a simple <a href, the user will download the file while staying on the current page. You can get this behavior with files that the browser has no plugin for (like .bin), or by sending a content-disposition header to force downloading.
Is there any method or header which keeps the user on the current page while still requesting the page? The idea is that the user clicks a link, the request is made, but the page doesn't change—like when downloading a file.
This could be done with an iframe I guess, which is not really pretty and makes another request when loading the page. Javascript is another obvious answer, but that's actually the reason for asking this question: compatibility with JS-less clients.
A form with the method set to HEAD is another ugly solution, but doesn't work anyway. Chromium ignores the method and simply performs a GET request...
Anymore ideas?
You could place an iframe on your page that is hidden. Then, give that iframe and id.
Use this id as the target of a link to the file you want to pull down.
I've created a demo at http://jsfiddle.net/dancrumb/N87nL/ to show you how this would work. Just style the iframe as being invisible and you're good to go
The page will load in the iframe, you'll stay on your page, it doesn't require JS. Oh boy!
Note that the iFrame doesn't have an initial value for src, so no request is made on page load.