Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Первый пример: (Картинка, переход на сайт при нажатии на неё без JS)
- <a href="https://google.com">
- <img border="0" alt="Google Test" src="google.png" width="100" height="100">
- </a>
- Второй пример (Присоеденение JS скрипта с переходом на сайт при нажатии на картинку без A тега):
- /js/main.js :
- var images = document.getElementsByTagName("img");
- for(var i = 0; i < images.length; i++) {
- var image = images[i];
- image.onclick = function(event) {
- window.location.href = "http://google.com/";
- };
- }
- /index.html:
- <html>
- <head>
- <script type="text/javascript" src="/js/main.js"></script>
- </head>
- <body>
- <img border="0" alt="Google Test" src="google.png" width="100" height="100">
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement