-1

There is a frame were a website will open i want that all links in the website is disabled except the one link suppose it to be a login link. Is it possible to disable all the links except one. So,this is what that is required.

<a href="" id="link_t" >link for exam</a>
        <iframe  id="frame" style=" width:100%; height: 700px;    margin:30px 0 0 0px;
          border-style: none; " src="" ></iframe>

on js file code is

var link_on_page=document.getElementById('link_t');
var divv=document.getElementById('frame');
link_on_page.addEventListener('click', function(e) {
    e.preventDefault();
        divv.src= "some_link"; 
    requestFullscreen(document.documentElement);
   });

I am calling third part website in a frame and do not want that links should open just the login link only just want to diable all links except the one on the third party website.

Daniel Beck
  • 20,653
  • 5
  • 38
  • 53

1 Answers1

0

Disabling all links can except one can be accomplished like so:

function disableAllLinks(){
// x now contains a live collection of anchor elements
let x = document.getElementsbyTagName('a');
let j = 0;
while (x[j]){
x[j].setAttribute('href', '');
j++
}

Then enable the reference you want using the same idea but with

x = document.getElementbyId('someId');
x.setAttribute('href', 'linkgoeshere');

This is just a quick simple example that uses the DOM You would then include a call to the function in the 'onclick' event function that loads the new page.

  • The iframe is a different `document`; this would need to run against the iframe's `.contentDocument.body` (if it were a first-party iframe.) – Daniel Beck Feb 03 '18 at 19:27
  • Sorry I assumed the link was outside of the iframe, because the code is incomplete; it looks like the link is not included in the iframe and the question is not in very clear and concise English I just gave a quick basic example on how it is done – Matthew Lagerwey Feb 03 '18 at 20:23
  • gah, you might be right, rereading the question I really can't tell anymore – Daniel Beck Feb 03 '18 at 20:29