Bind event to Iframe inside aspx page using Javascript - javascript

I have an aspx page in one of my .Net Web application. Inside which I am having iFrame that show a URL content.
My requirement is to restrict user from using right click option. I have already implemented the Javascript code for this, but it is working only outside the iFrame on the page NOT inside the iFrame i.e. when I run the project and right click somewhere outside the frame it shows proper error message but when I right click inside the frame it, allows the user to right click (View source).
Any idea how to achieve the desired result?

Related

JS Disable browser back button as soon as your page is ready

I am trying to disable the browser back button via JS code and have already seen lot of answers like
How can I stop the browser back button using JavaScript?
and
Trying to disable the browser's back button
But my problem is unique, The issue is that once my page is loaded and I don't click inside the document (Anywhere on the page) my browser back button still function the way it use to.
But If I click inside the document/page, all the above scripts and code works properly.
So the I want to ask that if there is any way I can make the document(page) active somehow so that if the user click directly on back button without clicking inside the page, They should not go back.

Wordpress, how to debug Javascript to check a specific behavior

I need to debug Javascript to check which function is called on a specific behavior.
To be more specific, when we click inside an iframe, all the page or at least the iframe is reloaded, so loaded 2 times.
For example, if you take a look at this page:
https://artetcadres.fr/art-et-images/#collection/hopper/
and click on the artist "Klimt", the main page activate a javascript function, display this image on the entire page and reload the iframe content.
I tried with the Chrome Devtools but can't figure out which function is called display the image "Loading..." and reload the iframe.
It's reloaded maybe because the url is dynamically updated. The anchor #collection/hopper/ will become #collection/klimt/.
This strange behavior appeared after an wordpress upgrade.

Content of iframe not opening in iframe only

I have a base page in which am using a Iframe of different domain.
Content gets render but if user click on any link rendered inside iframe it get open as normal page.
I want it to be opened in Iframe only.
for information, I can control my base page as well as application hosted on different domain.. which i want to so in iframe.
In simple words whole site that is opened in iframe, user should be able to do his work in iframe only. click on any link inside iframe should not open in browser. so that I can create a central application which can open my application(Existing) in iframe. As well as if user open the application seperatly it can also work.
If you don't have access to the code of the iFrame page you won't have a chance of doing this.
See: https://en.wikipedia.org/wiki/Cross-site_scripting
Technically, you could use .postmessage() to get the child content inside the iframe to send a message to the parent to change the iframe source on button clicks.
Note, this will only work if you have control of the child code getting rendered inside the iframe, which I cannot tell from your question.
Example, in your child site, inside the iframe, it would need code to send to the parent page (outside the iframe) when you click INSIDE the iframe site:
self.parent.postMessage("stringSayingDoSomething", "*");
Then, your parent site has an event listener set up to receive the message and perform an action.. that action can be doing something on the parent side.. or, sending a message back down to the child site to do something instead:
window.addEventListener("message", receiveMessage, false);
function receiveMessage(event) {
switch (message) {
case "stringSayingDoSomething":
DoMyFunctionNowThatChildFrameHasToldMeTo();
break;
Here is another question on stack overflow addressing the issue: Communicating cross-origin from parent to child iframe

How to redirect to parent window after logging in from iframe window?

I am using an Iframe window to display the login form of another website. And what I want is the user should go to that particular site after logging in(even if logging in fails, any click on any link in that iframe should take the user to that site in the full window(parent window).
As long as the links (within the iFrame) are part of the other page, you can't "hijack" their target. You would have to have the means and ability to modify the target attribute of each link to point to _parent or use javascript to reference the window.parent.
Based on what you're saying (you're logging in to a different domain and the page is not part of your site) this wouldn't be possible without implementing some kind of proxy where you could modify the contents between page visits.

How can I remove an iframe within an iframe on an external web page like Pinterest's bookmarklet?

I am in the process of making a bookmarklet that allows users to highlight text on an external web page.
It runs JavaScript code that appends a JavaScript file from my server to the current web page that takes the title of the current web page, the URL of the current web page, and then the highlight text of the current web page. Finally, the user would click a button to submit the data to my web server to be saved into the database.
I have two ways of doing this: (1) have a popup with the data in the URL as parameters, or (2) to have an iframe inserted into the current web page with a form to submit the data.
In the one with the popup (1), the users browser auto blocks the popup for every domain. How do I get around this? It seems like Facebook share and twitter tweet buttons bypass the popup blocker though...
In the one with the iframe (2), I want to remove the iframe from the DOM after submitting data. However, if I'm on another domain, I get an error saying I am denied access because of origin policy something. I know it's possible because Pinterest's bookmarklet does this, it inserts an iframe then removes it from the current DOM.
I am looking for information on how these solutions work, so I can do something similar with my bookmarklet.
I resolved this by adding a post message callback after saving the data from the iframe.

Categories

Resources