Тег А, атрибут target

Save Target As in Javascript

I have a bunch of links that point directly to powerpoint files. When the user clicks on these, they launch powerpoint instead of downloading it, but it also launches as just the slideshow (although its .ppt), and there is no way to print without right clicking the link, and choosing save target as, so they can download and then save/open it. Is there a way to invoke the save target as in javascript to bring up what would happen if the user right clicked a link and did the same?

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.

GET A PERSONALIZED SOLUTION

Right, this can’t be done using pure (client-side) Javascript. You need a server-side language to solve this ellegantly. The trick is to change the HTTP header, like so:

Content-disposition: attachment; filename=fname.ext

With PHP, you can use the header-statement,
with ASP, you can use the Response.AddHeader statement (as pointed out in the link adilkhan provided).

Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.

Put this line on that top of your page

Response.AddHeader «content-disposition»,»att achment; filename=fname.pdf»

and save it as ASP extension.
MAke sure your server supports ASP

My language of preference is PHP, so — taken from the manual:

— cut here —
If you want the user to be prompted to save the data you are sending, such as a generated PDF file, you can use the Content-Disposition header to supply a recommended filename and force the browser to display the save dialog.

header(«Content-type: application/ppt»);
header(«Content-Dispositio n: attachment; filename=downloaded.ppt»);

/* . output ppt file . */
?>
— cut here —

Fill in the correct filename after «filename=»
After these headers you need to dump the powerpoint file. PHP has some statements to do just that, fpassthru for example.

The link to microsoft above, gives a VB example (not really my thing).

Note that the headers alone don’t start the download: you need to dump the file also. The headers just say what’s ahead.

Источник

Атрибут target

По умолчанию, при переходе по ссылке документ открывается в текущем окне или фрейме. При необходимости, это условие может быть изменено атрибутом target тега . В XHTML применение этого атрибута запрещено.

Синтаксис

Обязательный атрибут

Значения

В качестве значения используется имя окна или фрейма, заданное атрибутом name . Если установлено несуществующее имя, то будет открыто новое окно. В качестве зарезервированных имен используются следующие.

_blank Загружает страницу в новое окно браузера. _self Загружает страницу в текущее окно. _parent Загружает страницу во фрейм-родитель, если фреймов нет, то это значение работает как _self . _top Отменяет все фреймы и загружает страницу в полном окне браузера, если фреймов нет, то это значение работает как _self .

Значение по умолчанию

Валидация

Использование этого атрибута осуждается спецификацией HTML, валидный код получается только при использовании переходного .

      

Открыть в новом окне

Не выкладывайте свой код напрямую в комментариях, он отображается некорректно. Воспользуйтесь сервисом cssdeck.com или jsfiddle.net, сохраните код и в комментариях дайте на него ссылку. Так и результат сразу увидят.

Читайте также:  Php http rest server

Типы тегов

HTML5

Блочные элементы

Строчные элементы

Универсальные элементы

Нестандартные теги

Осуждаемые теги

Видео

Документ

Звук

Изображения

Объекты

Скрипты

Списки

Ссылки

Таблицы

Текст

Форматирование

Формы

Фреймы

Источник

Save Target as.

How do I make a button that will bring up the download box for something on my website, without the user having to right-click and select «Save Target as. » .
Thanks
😆 Martin 😆

  • 8 Contributors
  • 25 Replies
  • 984 Views
  • 5 Months Discussion Span
  • Latest Post 17 Years Ago Latest Post by tgreer

You can’t. This is fundamental «user interface» 101. A programmer shouldn’t attempt to force actions that are historically under user control. Also, what you’re attempting violates the browser security model. Just imagine the havoc that would be caused if a web page could «silently download» anything as soon as you …

It can’t be done with HTML, CSS or JavaScript, the topics covered in this forum. What akadez is referring to are some possible techniques in ASP.NET, a server-side language. Daniweb has an ASP.NET forum, if you code in that language.

Most of your visitors will have .zip files set to offer as download rather than process automatically so you could upload in that format. There is also code that can be put in the .htaccess file to force what you want if your site is running on an apache server.

You can’t. This is fundamental «user interface» 101. A programmer shouldn’t attempt to force actions that are historically under user control. Also, what you’re attempting violates the browser security model. Just imagine the havoc that would be caused if a web page could «silently download» anything as soon as you …

I don’t mind the question, but you’re asking it in the wrong spot! Daniweb has a forum specifically for these types of issues: http://www.daniweb.com/techtalkforums/forum64.html

If you’ll peruse that forum, I think you’ll get the education you seek! If not, feel free to post a new thread there. No …

All 25 Replies

You can’t. This is fundamental «user interface» 101. A programmer shouldn’t attempt to force actions that are historically under user control. Also, what you’re attempting violates the browser security model. Just imagine the havoc that would be caused if a web page could «silently download» anything as soon as you browse to it. I understand you simply want the dialog to pop up, but it’s still not allowed.

The future is web applications, and needs to provide the same capabilities as a WinForms, if the developer deems so. 90% of my sites are intranet based, so I do not have the fear of anonymous users. If you are using the .NET framework you have some options. You have the ability to create a server-side method or page dedicated to writing the document to the response stream. This will cause the parent page to postback, but it will prompt for download. If you are looking to do this without postback you this can achieved using AjaxPro, http://ajaxpro.schwarz-interactive.de, or other any other Ajax frameworks.

What . — sorry I’m not with that at all can you explain again please? Martin P.S. I wanted to make a link on my website so that when someone clicked on it a .zip file would download — to save them right clicking and clicking on «Save Target as. » etc.

Читайте также:  Python abstract class method

It can’t be done with HTML, CSS or JavaScript, the topics covered in this forum. What akadez is referring to are some possible techniques in ASP.NET, a server-side language. Daniweb has an ASP.NET forum, if you code in that language.

Most of your visitors will have .zip files set to offer as download rather than process automatically so you could upload in that format. There is also code that can be put in the .htaccess file to force what you want if your site is running on an apache server.

You can’t. This is fundamental «user interface» 101. A programmer shouldn’t attempt to force actions that are historically under user control. Also, what you’re attempting violates the browser security model. Just imagine the havoc that would be caused if a web page could «silently download» anything as soon as you browse to it. I understand you simply want the dialog to pop up, but it’s still not allowed.

Excuse me but the idiot has arrived 😮 with a question . about your answer. Pages seem to download a lot of crap onto my machine when I browse the internet. I have gotten worms, spyware, and other malicious stuff without ever asking for it nor agreeing to it. *thinks I need to hide under the bed now as you are all probably dying laughing* but I really want to know. When you stop laughing at me will you please explain this to me? :rolleyes:

I don’t mind the question, but you’re asking it in the wrong spot! Daniweb has a forum specifically for these types of issues: http://www.daniweb.com/techtalkforums/forum64.html If you’ll peruse that forum, I think you’ll get the education you seek! If not, feel free to post a new thread there. No one will bite your head off; we try to be a friendly group.

Wait wait wait . what is being asked is a client-side technology, not server-side at all . Anything that would interact directly with the web browser — such as opening a dialog menu, would have to be a client-side script. Server side scripts can interact with files on the server, but you need something client side to interact with files or applications (in this case, the web browser) on the client side of things. I think this could be accomplished in DHTML (although I’m not sure specifically how to go about it), can it not?

Replace null with a filename (if you use frames, or if you want clicking the link on one page to save another one).

I don’t mind the question, but you’re asking it in the wrong spot! Daniweb has a forum specifically for these types of issues: http://www.daniweb.com/techtalkforums/forum64.html If you’ll peruse that forum, I think you’ll get the education you seek! If not, feel free to post a new thread there. No one will bite your head off; we try to be a friendly group.

Sorry but your answer just struck a cord in me because I just had such a bad worm that my antivirus company sent me a custom cleaner which killed all my file associations. I did figure out how to get them back. . well most of them . . but I still need to reformat. The guy who sent the custom cleaner when I called him bawling my head off told me that it was something I got from visiting a website. He looked through my history to try and determine where I got it and how and finally concluded that it was just dumped on me. And they said that they were glad that I had called them with info at hand because others would be calling soon as well. You said that guy couldn’t do something that I am not sure that I understand because :

what you’re attempting violates the browser security model. Just imagine the havoc that would be caused if a web page could «silently download» anything as soon as you browse to it.

But my antivirus guy says that it is why we get viruses and worms and other nasty things on our pc’s. So I guess that what I am really asking is what is the real truth here? I don’t need help, I want understanding.
Thanks for not laughing too hard at me tgreer.

Читайте также:  Text file type php

Источник

How do I make this to «save as HTML» instead of as it is «download as HTML»?

I am making an online web editor and I need this. How do I make this into a «save as» function instead of what it is a «download function»? The difference is that in «download as» you can not decide what name it should be, but in «save as» you can decide the save file name before it saves. So how do I make this to «save as», instead of «download as»? PS: if you could help me add a «load file» button too that works, that would be great.

     Download Above Code   

Your main() function doesn’t exist, your .onclick function doesn’t take a parameter, and html is undefined.

2 Answers 2

The below script makes use of some HTML5 features

function saveTextAsFile() < var textToSave = document.getElementById("inputTextToSave").value; var textToSaveAsBlob = new Blob([textToSave], ); var textToSaveAsURL = window.URL.createObjectURL(textToSaveAsBlob); var fileNameToSaveAs = document.getElementById("inputFileNameToSaveAs").value; var downloadLink = document.createElement("a"); downloadLink.download = fileNameToSaveAs; downloadLink.innerHTML = "Download File"; downloadLink.href = textToSaveAsURL; downloadLink.onclick = destroyClickedElement; downloadLink.style.display = "none"; document.body.appendChild(downloadLink); downloadLink.click(); > function destroyClickedElement(event) < document.body.removeChild(event.target); >function loadFileAsText() < var fileToLoad = document.getElementById("fileToLoad").files[0]; var fileReader = new FileReader(); fileReader.onload = function(fileLoadedEvent) < var textFromFileLoaded = fileLoadedEvent.target.result; document.getElementById("inputTextToSave").value = textFromFileLoaded; >; fileReader.readAsText(fileToLoad, "UTF-8"); >
  
Text to Save:
Filename to Save As:
Select a File to Load:

It would be useful to add that this doesn’t work in IE at all, and Edge wont «honour» the supplied filename

There is one tiny problem with that code of yours. And that it is, that it saves as TXT file and I want it to save as HTML file. How do I make it to save as HTML file?

As you see in the example above I did make it to save as a HTML file. The only problem was that it is fixed named as «code.html» unless i change the source values, but I want it to be changeble in the page but with that code I can not give it what name I want as for example MyName.html So what I needed was a way to save the file as HTML instead of downloading it because when downloading you can not add freely your own name as in saving as.

I was thinking more like what if the button was calling to a box before for name and after that it would be saved with the function I made. There for one could save it as HTML with no problem. But how to do that code?

Источник

Оцените статью